package com.itfenghuang.day15;

import java.io.*;
import java.net.Socket;

/*
文件上传的客户端
 */
public class A04_UploadClient {
    public static void main(String[] args) throws IOException {
//使用字节输入流读取要上传的文件
        FileInputStream fs = new FileInputStream("F:\\123.jpg");
//        创建Socket对象
        Socket sk = new Socket("127.0.0.1", 12333);
//        获取网络输出流
        OutputStream os = sk.getOutputStream();
        byte[] bys = new byte[1024];
        int len;
        System.out.println("11111");
        while ((len=fs.read(bys))!=-1){
            os.write(bys,0,len);
        }
        System.out.println("2222");
//        写一个终止序列出去
        sk.shutdownOutput();
//        循环读写
//        接收服务端回送的消息
        InputStream is = sk.getInputStream();
        int len1 = is.read(bys);
        System.out.println("3333");
        System.out.println(new String(bys,0,len1));
//        释放资源
                sk.close();
                fs.close();
    }
}
